# 计算 矩阵的幂
import numpy as np
from numpy.linalg import eig, inv
from numpy import diag

if __name__ == '__main__':
    matrix = np.array([
        [1, 5],
        [1, 6]
    ], np.int64)

    temp = np.eye(2)

    result = np.empty((2, 2))

    # 利用公式进行计算
    for _ in range(5):
        result[0, 0] = temp[0, 0] * matrix[0, 0] + temp[0, 1] * matrix[1, 0]
        result[0, 1] = temp[0, 0] * matrix[0, 1] + temp[0, 1] * matrix[1, 1]
        result[1, 0] = temp[1, 0] * matrix[0, 0] + temp[1, 1] * matrix[1, 0]
        result[1, 1] = temp[1, 0] * matrix[0, 1] + temp[1, 1] * matrix[1, 1]
        temp = result

    print(result)

    eigenvalues, eigenvectors = eig(matrix)
    lambda_matrix = diag(eigenvalues)
    inverse_eigenvalues = inv(eigenvectors)

    temp = np.eye(2)

    for _ in range(5):
        for i in range(matrix.shape[0]):
            temp[i][i] = temp[i][i] * lambda_matrix[i][i]

    result2 = eigenvectors @ temp @ inverse_eigenvalues

    print(result2)





